package com.clone;

/**
 * @Author: fxy
 * @Date: 2022/03/10/13:46
 * @Description:
 */
public class Test1 implements Cloneable{
    String s;
    A a;
    @Override
    public Test1 clone() throws CloneNotSupportedException {

        Test1 clone =(Test1) super.clone();
        clone.s = new String(this.s);
        clone.a = this.a.clone();
        return clone;
    }

    public static void main(String[] args) throws CloneNotSupportedException {
        Test1 t1 = new Test1();
        t1.s =new String("123456");
        t1.a = new A();
        t1.a.a = 5;
        Test1 t2 = t1.clone();
        System.out.println(t1.s==t2.s);
        System.out.println(t1.a==t2.a);
    }
}
class A implements Cloneable{
    int a;
    @Override
    public A clone() throws CloneNotSupportedException {
        return (A) super.clone();
    }
}
